package cn.kin.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.kin.dao.StaffMapper;
import cn.kin.pojo.Staff;
import cn.kin.service.StaffService;
import cn.kin.tools.PageSupport;

@Service
public class StaffServiceImpl implements StaffService{

	@Resource
	private StaffMapper staffMapper;
	
	//登录
	public Staff login(String staffNum,String pwd) {
		try {
			Staff staff=staffMapper.selectByStaffNum(staffNum);
				if(staff.getPassword().equals(pwd)) {
					return staff;
					}
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return null;
	}
	
	@Override
	public List<Staff> findByMap(Map map) {
		// TODO Auto-generated method stub
		List<Staff> list=null;
		try {
			int pageNo=((PageSupport)map.get("page")).getCurrentPageNo();
			int size=((PageSupport)map.get("page")).getPageSize();
			map.put("from",(pageNo-1)*size);
			map.put("size",size);
			list=staffMapper.selectByMap(map);
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			list=null;
		}
		return list;
	}
	
	@Override
	public int findCountByMap(Map map) {
		// TODO Auto-generated method stub
		int result=0;
		try {
			result=staffMapper.selectCountByMap(map);
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			result=-1;
		}
		return result;
	}
}
